import UIKit

//初始化一个字典的4中写法
var dict1:Dictionary<String,Double> = [:]
var dict2 = Dictionary<String,Double>()
var dict3:[String:Double] = [:]
var dict4 = [String:Double]()


//利用字面量语法创建的可变字典
var movieRatings = ["Donnie Darko":4,
                    "Chungking Express":5,
                    "Dark City":4]

//修改和访问字典
print("i have rated \(movieRatings.count) movies")

let darkRating = movieRatings["Donnie Darko"]

movieRatings["Dark City"] = 5
movieRatings


//通过updateValue方法来修改字典中的值,会返回旧值,是一个可选项
let oldRating:Int? = movieRatings.updateValue(5, forKey: "Donnie Darko")
if let lastRating = oldRating,
   let currentRating = movieRatings["Donnie Darko"]{
    print("Old rating:\(lastRating);current rating:\(currentRating)")
}

